<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tabarea {
            margin: 100px auto;
            width: 500px;
        }
        .tab {
            
            height: 40px;
            background-color: #ccc;
            border-bottom: 1px solid red;
        }
        li {
            list-style: none;
            cursor: default;
        }
        ul li {
            float: left;
            width: 100px;
            height: 40px;
            background-color: #ccc;
            line-height: 40px;
            text-align: center;
        }
        .current {
            background-color: rgb(192, 28, 28);
            color: aliceblue;
        }
        .content {
            font-size: 30px;
            font-weight: bold;
            display: none;
        }
    </style>
</head>
<body>
    <div class="tabarea">
        <div class="tab">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
            </ul>
        </div>
        <div class="content" style="display: block;">真牛哇！</div>
        <div class="content">真不错！</div>
        <div class="content">真的香！</div>
        <div class="content">针布戳！</div>
    </div>
</body>
<script>
    var lis = document.querySelector('ul')
    var li = lis.querySelectorAll('li')
    var cont = document.querySelectorAll('.content')
    for (var i = 0;li.length > i;i++ ) {
        li[i].setAttribute('data-index',i);
        li[i].onclick = function(){
            for (var i = 0;i<li.length;i++){
                li[i].className = ''
                cont[i].style.display = 'none'
            }
            this.className = 'current'
            var index = this.getAttribute('data-index')
            cont[index].style.display = 'block'
        }
    }
</script>
</html>